home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 114 / PC Guia 114.iso / Software / Produtividade / Apache 2.0.52 / apache_2.0.52-win32-x86-no_ssl.msi / Data.Cab / F277220_apr_poll.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-02-13  |  9.9 KB  |  253 lines

  1. /* Copyright 2000-2004 The Apache Software Foundation
  2.  *
  3.  * Licensed under the Apache License, Version 2.0 (the "License");
  4.  * you may not use this file except in compliance with the License.
  5.  * You may obtain a copy of the License at
  6.  *
  7.  *     http://www.apache.org/licenses/LICENSE-2.0
  8.  *
  9.  * Unless required by applicable law or agreed to in writing, software
  10.  * distributed under the License is distributed on an "AS IS" BASIS,
  11.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12.  * See the License for the specific language governing permissions and
  13.  * limitations under the License.
  14.  */
  15.  
  16. #ifndef APR_POLL_H
  17. #define APR_POLL_H
  18. /**
  19.  * @file apr_poll.h
  20.  * @brief APR Poll interface
  21.  */
  22. #include "apr.h"
  23. #include "apr_pools.h"
  24. #include "apr_errno.h"
  25. #include "apr_inherit.h" 
  26. #include "apr_file_io.h" 
  27. #include "apr_network_io.h" 
  28.  
  29. #if APR_HAVE_NETINET_IN_H
  30. #include <netinet/in.h>
  31. #endif
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif /* __cplusplus */
  36.  
  37. /**
  38.  * @defgroup apr_poll Poll Routines
  39.  * @ingroup APR 
  40.  * @{
  41.  */
  42.  
  43. /**
  44.  * @defgroup apr_poll_opt Poll options
  45.  * @{
  46.  */
  47. #define APR_POLLIN    0x001     /**< Can read without blocking */
  48. #define APR_POLLPRI   0x002     /**< Priority data available */
  49. #define APR_POLLOUT   0x004     /**< Can write without blocking */
  50. #define APR_POLLERR   0x010     /**< Pending error */
  51. #define APR_POLLHUP   0x020     /**< Hangup occurred */
  52. #define APR_POLLNVAL  0x040     /**< Descriptior invalid */
  53. /** @} */
  54.  
  55. /** Used in apr_pollfd_t to determine what the apr_descriptor is */
  56. typedef enum { 
  57.     APR_NO_DESC,                /**< nothing here */
  58.     APR_POLL_SOCKET,            /**< descriptor refers to a socket */
  59.     APR_POLL_FILE,              /**< descriptor refers to a file */
  60.     APR_POLL_LASTDESC           /**< descriptor is the last one in the list */
  61. } apr_datatype_e ;
  62.  
  63. /** Union of either an APR file or socket. */
  64. typedef union {
  65.     apr_file_t *f;              /**< file */
  66.     apr_socket_t *s;            /**< socket */
  67. } apr_descriptor;
  68.  
  69. /** @see apr_pollfd_t */
  70. typedef struct apr_pollfd_t apr_pollfd_t;
  71.  
  72. /** Poll descriptor set. */
  73. struct apr_pollfd_t {
  74.     apr_pool_t *p;              /**< associated pool */
  75.     apr_datatype_e desc_type;   /**< descriptor type */
  76.     apr_int16_t reqevents;      /**< requested events */
  77.     apr_int16_t rtnevents;      /**< returned events */
  78.     apr_descriptor desc;        /**< @see apr_descriptor */
  79.     void *client_data;          /**< allows app to associate context */
  80. };
  81.  
  82. /**
  83.  * Setup the memory required for poll to operate properly
  84.  * @param new_poll The poll structure to be used. 
  85.  * @param num The number of socket descriptors to be polled.
  86.  * @param cont The pool to operate on.
  87.  * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  88.  */
  89. APR_DECLARE(apr_status_t) apr_poll_setup(apr_pollfd_t **new_poll, 
  90.                                          apr_int32_t num,
  91.                                          apr_pool_t *cont);
  92.  
  93. /**
  94.  * Poll the sockets in the poll structure
  95.  * @param aprset The poll structure we will be using. 
  96.  * @param numsock The number of sockets we are polling
  97.  * @param nsds The number of sockets signalled.
  98.  * @param timeout The amount of time in microseconds to wait.  This is 
  99.  *                a maximum, not a minimum.  If a socket is signalled, we 
  100.  *                will wake up before this time.  A negative number means 
  101.  *                wait until a socket is signalled.
  102.  * @remark
  103.  * <PRE>
  104.  * The number of sockets signalled is returned in the second argument. 
  105.  *
  106.  *        This is a blocking call, and it will not return until either a 
  107.  *        socket has been signalled, or the timeout has expired. 
  108.  * </PRE>
  109.  */
  110. APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t numsock,
  111.                                    apr_int32_t *nsds, 
  112.                                    apr_interval_time_t timeout);
  113.  
  114. /**
  115.  * Add a socket to the poll structure.
  116.  * @param aprset The poll structure we will be using. 
  117.  * @param sock The socket to add to the current poll structure. 
  118.  * @param event The events to look for when we do the poll.  One of:
  119.  * <PRE>
  120.  *            APR_POLLIN       signal if read will not block
  121.  *            APR_POLLPRI      signal if prioirty data is availble to be read
  122.  *            APR_POLLOUT      signal if write will not block
  123.  * </PRE>
  124.  * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  125.  */
  126. APR_DECLARE(apr_status_t) apr_poll_socket_add(apr_pollfd_t *aprset, 
  127.                                               apr_socket_t *sock,
  128.                                               apr_int16_t event);
  129.  
  130. /**
  131.  * Modify a socket in the poll structure with mask.
  132.  * @param aprset The poll structure we will be using. 
  133.  * @param sock The socket to modify in poll structure. 
  134.  * @param events The events to stop looking for during the poll.  One of:
  135.  * <PRE>
  136.  *            APR_POLLIN       signal if read will not block
  137.  *            APR_POLLPRI      signal if priority data is available to be read
  138.  *            APR_POLLOUT      signal if write will not block
  139.  * </PRE>
  140.  * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  141.  */
  142. APR_DECLARE(apr_status_t) apr_poll_socket_mask(apr_pollfd_t *aprset,
  143.                                                apr_socket_t *sock,
  144.                                                apr_int16_t events);
  145. /**
  146.  * Remove a socket from the poll structure.
  147.  * @param aprset The poll structure we will be using. 
  148.  * @param sock The socket to remove from the current poll structure. 
  149.  * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  150.  */
  151. APR_DECLARE(apr_status_t) apr_poll_socket_remove(apr_pollfd_t *aprset, 
  152.                                                  apr_socket_t *sock);
  153.  
  154. /**
  155.  * Clear all events in the poll structure.
  156.  * @param aprset The poll structure we will be using. 
  157.  * @param events The events to clear from all sockets.  One of:
  158.  * <PRE>
  159.  *            APR_POLLIN       signal if read will not block
  160.  *            APR_POLLPRI      signal if priority data is available to be read
  161.  *            APR_POLLOUT      signal if write will not block
  162.  * </PRE>
  163.  * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  164.  */
  165. APR_DECLARE(apr_status_t) apr_poll_socket_clear(apr_pollfd_t *aprset, 
  166.                                                  apr_int16_t events);
  167.  
  168. /**
  169.  * Get the return events for the specified socket.
  170.  * @param event The returned events for the socket.  One of:
  171.  * <PRE>
  172.  *            APR_POLLIN       Data is available to be read 
  173.  *            APR_POLLPRI      Priority data is availble to be read
  174.  *            APR_POLLOUT      Write will succeed
  175.  *            APR_POLLERR      An error occurred on the socket
  176.  *            APR_POLLHUP      The connection has been terminated
  177.  *            APR_POLLNVAL     This is an invalid socket to poll on.
  178.  *                             Socket not open.
  179.  * </PRE>
  180.  * @param sock The socket we wish to get information about. 
  181.  * @param aprset The poll structure we will be using. 
  182.  * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  183.  */
  184. APR_DECLARE(apr_status_t) apr_poll_revents_get(apr_int16_t *event, 
  185.                                           apr_socket_t *sock,
  186.                                           apr_pollfd_t *aprset);
  187.  
  188. /* General-purpose poll API for arbitrarily large numbers of
  189.  * file descriptors
  190.  */
  191.  
  192. /** Opaque structure used for pollset API */
  193. typedef struct apr_pollset_t apr_pollset_t;
  194.  
  195. /**
  196.  * Setup a pollset object
  197.  * @param pollset  The pointer in which to return the newly created object 
  198.  * @param size The maximum number of descriptors that this pollset can hold
  199.  * @param p The pool from which to allocate the pollset
  200.  * @param flags Optional flags to modify the operation of the pollset
  201.  *              (reserved for future expansion)
  202.  */
  203. APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset,
  204.                                              apr_uint32_t size,
  205.                                              apr_pool_t *p,
  206.                                              apr_uint32_t flags);
  207.  
  208. /**
  209.  * Destroy a pollset object
  210.  * @param pollset The pollset to destroy
  211.  */
  212. APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t *pollset);
  213.  
  214. /**
  215.  * Add a socket or file descriptor to a pollset
  216.  * @param pollset The pollset to which to add the descriptor
  217.  * @param descriptor The descriptor to add
  218.  * @remark If you set client_data in the descriptor, that value
  219.  *         will be returned in the client_data field whenever this
  220.  *         descriptor is signalled in apr_pollset_poll().
  221.  */
  222. APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset,
  223.                                           const apr_pollfd_t *descriptor);
  224.  
  225. /**
  226.  * Remove a descriptor from a pollset
  227.  * @param pollset The pollset from which to remove the descriptor
  228.  * @param descriptor The descriptor to remove
  229.  */
  230. APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset,
  231.                                              const apr_pollfd_t *descriptor);
  232.  
  233. /**
  234.  * Block for activity on the descriptor(s) in a pollset
  235.  * @param pollset The pollset to use
  236.  * @param timeout Timeout in microseconds
  237.  * @param num Number of signalled descriptors (output parameter)
  238.  * @param descriptors Array of signalled descriptors (output parameter)
  239.  */
  240. APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset,
  241.                                            apr_interval_time_t timeout,
  242.                                            apr_int32_t *num,
  243.                                            const apr_pollfd_t **descriptors);
  244.  
  245. /** @} */
  246.  
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250.  
  251. #endif  /* ! APR_POLL_H */
  252.  
  253.